package lv.clientedisqueria.view.principal;

import java.awt.BorderLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JFrame;

import lv.clientedisqueria.controller.principal.PrincipalController;

/**
 * Esta es la vista principal de la aplicacion 
 */
@SuppressWarnings("serial")
public class PrincipalView extends JFrame implements Observer {

	private PrincipalController principalController;
	
	private PrincipalMenuBarView principalMenuBarView;
	private PrincipalMenuBoton principalMenuBoton;
	private PrincipalTabbedPaneView principalTabbedPaneView;
	
	public PrincipalView() {
		this.principalController = new PrincipalController();
		iniciarVista();
	}

	private void iniciarVista() {
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		this.setTitle("Disqueria");
		this.setSize(1000, 600);
		this.setLocation(150, 100);
		this.setJMenuBar(getPrincipalMenuBarView());
		this.setLayout(new BorderLayout());
		this.add(getPrincipalMenuButton(), BorderLayout.NORTH);
		this.add(getPrincipalTabbedPaneView(), BorderLayout.CENTER);
	}

	private PrincipalMenuBoton getPrincipalMenuButton() {
		if(principalMenuBoton == null){
			principalMenuBoton = new PrincipalMenuBoton(this.principalController);
		}
		return principalMenuBoton;
	}

	public void mostrar() {
		this.setVisible(true);
	}

	private PrincipalMenuBarView getPrincipalMenuBarView() {
		if(principalMenuBarView == null){
			principalMenuBarView = new PrincipalMenuBarView(this.principalController);
		}
		return principalMenuBarView;
	}

	private PrincipalTabbedPaneView getPrincipalTabbedPaneView() {
		if (principalTabbedPaneView == null) {
			principalTabbedPaneView = new PrincipalTabbedPaneView();
			principalController.addObserver(principalTabbedPaneView);
		}
		return principalTabbedPaneView;
	}
	
	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub
	}
}